import fetch from '../utils/fetch';
import exportFile from '../utils/exportFile';
//根据表名获取表结构
export function getColumns(key){
  return fetch({
    url:"/api/publicController/getColumns",
    method:"get",
    params: { key }
  })
}

export function selectTree(ciKey,parameterList,page,pageSize,sortList,searchType,returnFiled) {
  if(parameterList.length<1)parameterList=[];
  const data = {
    page:page,
    pageSize:pageSize,
    ciKey,
    sortList,
    paraList:parameterList,
    searchType
  };
  if(returnFiled && returnFiled.length>0){
    data.returnFiled=returnFiled
  }
  return fetch({
    url: '/api/publicController/selectTree/'+ciKey,
    method: 'post',
    data
  });
}
export function selectTree2(ciKey,page,pageSize,lookupList,searchType) {
  // if(parameterList.length<1)parameterList=[];
  const data = {
    page:page,
    pageSize:pageSize,
    ciKey,
    // paraList:parameterList,
    lookupList,
    searchType
  };
  return fetch({
    url: '/api/publicController/getValueByAggregation/'+ciKey,
    method: 'post',
    data
  });
}

//根据表名获取表数据通过后台getValueByApp
export function getValue(ciKey,parameterList,page,pageSize,sortList) {
  if(parameterList.length<1)parameterList=[];
  const data = {
    page:page,
    pageSize:pageSize,
    ciKey,
    sortList,
    paraList:parameterList
  };
  return fetch({
    url: '/api/publicController/getValueByApp/'+ciKey,
    method: 'post',
    data
  });
}
//
export function getInstruction(ciKey,parameterList,page,pageSize,sortList) {
  console.log(ciKey)
  if(parameterList.length<1)parameterList=[];
  const data = {
    page:page,
    pageSize:pageSize,
    sortList,
    paraList:parameterList
  };
  return fetch({
    url: '/api/supply/front/getInstruction/'+ciKey,
    method: 'post',
    data
  });
}

//根据表名获取表数据通过后台getValueByApp 只返回id 和 name
export function getIdName(ciKey,parameterList,page,pageSize,returnFiled,sortList) {
  if(parameterList.length<1)parameterList=[];
  const data = {
    page:page,
    pageSize:pageSize,
    ciKey,
    sortList,
    paraList:parameterList,
    // returnFiled:["_id",...returnFiled]
  };
  if(returnFiled.length>0){
    data.returnFiled=["_id",...returnFiled]
  }else{
    data.returnFiled=["_id","name",'icon']
  }
  return fetch({
    url: '/api/publicController/getValueByApp/'+ciKey,
    method: 'post',
    data
  });
}

//根据表名获取表数据通过后台getValueByShell
export function getValueByShell(ciKey,parameterList,page,pageSize,sortList) {
  if(parameterList.length<1)parameterList=[];
  const data = {
    page:page,
    pageSize:pageSize,
    ciKey,
    sortList,
    paraList:parameterList
  };
  return fetch({
    url: '/api/publicController/getValueByShell/'+ciKey,
    method: 'post',
    data
  });
}
//添加数据
export function addValue(ciKey,para) {
  return fetch({
    url: '/api/publicController/addValue/'+ciKey,
    method: 'post',
    data:para
  });
}
//保存数据
export function saveValue(ciKey,para) {
  return fetch({
    url: '/api/publicController/saveValue/'+ciKey,
    method: 'post',
    data:para
  });
}

//删除数据
export function deleteValue(ciKey,para) {
  const data = para;
  return fetch({
    url: '/api/publicController/deleteByid/'+ciKey,
    method: 'post',
    data
  });
}

export function updateValue(ciKey,para) {
  // console.log(JSON.stringify(para))
  return fetch({
    url: '/api/publicController/updateValueByid/'+ciKey,
    method: 'post',
    data:para
  });
}


export function login(name,password,captchaKey,captchaValue){
  const data={
    name,
    password,
    captchaKey,
    captchaValue
  };
  return fetch({
    url:"/api/user/login",
    method:"post",
    data
  })
}


export function initSystemTable(){
  return fetch({
    url:"/api/publicController/initSystemTable",
    method:"get"
  })
}

export function role(_id){
  const data={
    _id
  }
  return fetch({
    url:"/api/user/menu",
    method:"post",
    data
  })
}

export function getCaptcha(){
  return fetch({
    url:"/api/user/captcha",
    method:"get"
  })
}
//查询字典表
export function getTreeData(ciKey) {
  return fetch({
    url: '/api/govern/tree/'+ciKey,
    method: 'get'
  });
}
// 导出单表文件
export function downLoad(para){
  exportFile({
    url: '/api/publicController/getOrderExcel3',
    method: 'post',
    responseType: 'blob',
    data:para
  });
}
// 导出所有表文件
export function downLoad2(para){
  exportFile({
    url:'/api/publicController/downloadAll',
    method:"post",
    responseType:'blob',
    data:para
  })
}

// 全文搜索
export function fullSearch(para){
  const data = {
    
  }
  return fetch({
    url:'/api/user/getESData',
    method:"post",
    data:para
  })
}
// export function upExl(para){
//   return fetch({
//     url:"/api/user/upload",
//     method:"post",
//     headers: { 
//       'Content-Type': 'multipart/form-data'
//      },
//     data:para
//   })
// }
export function selectTreeAll(ciKey,parameterList,page,pageSize,sortList,searchType,returnFiled){
  if(parameterList.length<1)parameterList=[];
  const data = {
    page:page,
    pageSize:pageSize,
    ciKey,
    sortList,
    paraList:parameterList,
    searchType
  };
  if(returnFiled && returnFiled.length>0){
    data.returnFiled=returnFiled
  }
  return fetch({
    url:"/api/user/getIndividuation/"+ciKey,
    method:"post",
    data:data
  })
}

export function getMTForWorkInstruction(data){
  return fetch({
    url:"/apj/production-jcw/getMTForWorkInstruction.do?system="+data,
    // url:"http://10.192.32.232:8007/production-jcw/getMTForWorkInstruction.do?system="+data,
    method:"get"
  })
}

export function publishInstruction(data){
  return fetch({
    url:"/api/token/supply/publishInstruction",
    method:"post",
    data:data
  })
}
export function getDeviceListByType1(){
  return fetch({
    url:"/api/GDXT/device-jcw/getDeviceListByType1.do",
    method:"get",
  })
}